import request from "../utils/request";

export function login(username, password) {
    return request.post('/user/login', {
        username,
        password
    })
}

// /logout 
export function logout(userId) {
    return request.get(`/logout?userId=${userId}`)
}

export function getUserInfo(username) {
    return request.get(`/user/info?username=${username}`)
}
export function getUserInfoById(id) {
    return request.get(`/user/${id}`)
}

export function checkLogin(userId) {
    return request.get(`/checkLogin?userId=${userId}`)
}

export function register(username, password, phoneNumber, email) {
    return request.post('/user/register', {
        username,
        password,
        email,
        phoneNumber
    })
}

/**
 * 头像上传
 */
export function uploadAvatar(data) {
    return request.post('/uploadAvatar', {
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        data
    })
}

/**
 *
 * @param {修改用户} user
 * @returns
 */
export function updateUserInfo(user) {
    return request.put(`/user/info`, {
        id: user.id,
        avatar: user.avatar,
        email: user.email,
        nickName: user.nickName,
        phoneNumber: user.phoneNumber

    })
}

